﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraGrid.Views.Grid;
using COMOSOFT.Class;

namespace COMOSOFT.OrderBusiness.Forms
{
    public partial class FrmCostingGaneral : Form
    {
        ClassShare cls = new ClassShare("FrmCostingGaneral");
        int Year;
        object Cus;
        FrmPreviewCosting frPvCost = null;
        int CMID;
        FrmCostingDetails frmCD = null;
        public FrmCostingGaneral(int _Year, object _Cus)
        {
            InitializeComponent();
            this.Year = _Year;
            this.Cus = _Cus;
        }

        #region[LoadData]
        public void LoadData()
        {
            try
            {
                sp_CostingGaneralTableAdapter.Fill(dataSetOrderManagement.sp_CostingGaneral, Year, Cus);
                bandedGridView_CostingGaneral.ColumnPanelRowHeight = 30;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        #endregion

        #region[EventContext]
        private void previewToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {               
                frPvCost = new FrmPreviewCosting(bandedGridView_CostingGaneral);
                frPvCost.LoadData();
                frPvCost.Show();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }       

        private void refreshToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LoadData();
        }

        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        #endregion

        private void bandedGridView_CostingGaneral_DoubleClick(object sender, EventArgs e)
        {
            GridView view = bandedGridView_CostingGaneral as GridView;
            if (view.FocusedRowHandle >= 0)
            {
                CMID = Convert.ToInt32(view.GetFocusedDataRow()["CMID"]);
                frmCD = new FrmCostingDetails(CMID) { MdiParent=ClassShare.frmain, Text="StyleNo: "+view.GetFocusedDataRow()["StyleNo"]};
                frmCD.LoadData();
                frmCD.Show();                
            }
        }
    }
}
